package com.elong.kafka.producer;

import java.util.Properties;
import java.util.Random;

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

import com.elong.common.util.ConfigProp;

public class TestProducer {

    public static void main(String[] args) {
	
	long events = 1;
	Random rnd = new Random();
	
	Properties props = new Properties();
	
	props.put("metadata.broker.list", ConfigProp.getParams("metadata.broker.list"));
	props.put("serializer.class", ConfigProp.getParams("serializer.class"));
	props.put("partitioner.class", ConfigProp.getParams("partitioner.class"));
	props.put("request.required.acks", ConfigProp.getParams("request.required.acks"));
	props.put("zookeeper.session.timeout.ms", "400000");
	
	ProducerConfig config = new ProducerConfig(props);
	
	Producer<String, String> producer = new Producer<>(config);
	
	for(long nEvents = 0; nEvents < events; nEvents++){
	    long runtime = System.currentTimeMillis();
	    String ip = "192.168.2." + rnd.nextInt(255);
	    String msg = runtime + ",www.elong.com," + ip;
	    KeyedMessage<String, String> data = new KeyedMessage<String, String>("test22", ip, msg);
	    producer.send(data);
	}
	producer.close();
    }
}
